package com.hystrix.command;

import com.hystrix.http.HttpPost;
import com.hystrix.util.Constant;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
 * Request Cache
 * 
 * 只能对每次请求中相同的请求进行缓存
 * 
 * 每次请求需要一个请求上下文HystrixRequestContext，不同上下文不是一份缓存
 * 
 * @author wangxh
 *
 */
public class RequestCacheCommand extends HystrixCommand<String> {

	private String cacheId;

	public RequestCacheCommand(String cacheId) {
		super(HystrixCommandGroupKey.Factory.asKey("GetServiceAInfoCommand"));
		this.cacheId = cacheId;
	}

	@Override
	protected String run() throws Exception {
		return HttpPost.httpPost(Constant.serviceBcache + "?cacheId=" + this.cacheId, "", "utf-8");
	}

	@Override
	protected String getCacheKey() {
		return cacheId;
	}

}
